{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Distance between bitstrings\n",
    "\n",
    "Here we will draw the histogram of the distance between two random bitstrings."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sdm as sdmlib\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "distances = []\n",
    "for i in xrange(5000):\n",
    "    b1 = sdmlib.Bitstring.init_random(1000)\n",
    "    b2 = sdmlib.Bitstring.init_random(1000)\n",
    "    distances.append(b1.distance_to(b2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEACAYAAAC08h1NAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAEABJREFUeJzt3X+MHOV9x/H31T9oCD3cUyT/wI7OcWIMEaXQFmibyAPF1K0izF/gSERX0uYfUoW0FcSmUn3+J3JTpUlKhSolBblVcUsJsuyKOHZdD0VKZFAx1MFcz3ZiBTvyJSrQokpWbPn6x/Ncdr139t3Nzu7M7vN+SaedmZ3be/bx+rPPfueZWZAkSZIkSZIkSZIkSZIkSVKNPQVMAEdnuO9PgIvAUNO2rcBxYAy4p+OtkySV7uPALUwP/lXAPuAHNIL/RuA1YBEwDJwAfq4rrZQkzdlswfwS8M4M2/8SeKxl2yZgF3AeOEUI/tvabJ8kqWRFRuSbgNPAf7ZsXxG3TzkNXFewXZKkDlk4z/2vBh4HNjRtG7jC/pPzbpEkqaPmG/xrCPX71+P6SuA/gNuBM4TaP033nZn2AGvWTJ48eXLeDZWkxJ0EPtytPzbMzLN6YOaDu4uB1YRGzvRpYFLBtm3bqm5CbdgXDfZFg33RQIkVlNlq/LuA7wBrgbeAh1pDvGn5GPBsvP0W8DCWe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GQ79IePPbC2wgrX4Y5tLgn+9zX86lV0bYDPzNbH+0m++WqZ/cNUx4dz9M+IediNsnaPxDryD0y5R+6qOvAI8SpvdOSbEfAFYDPwGeBl4Fvg68n/T6423gy8APgR8B7xLKHKn1Q7P5PvfW7WeYQ590M/hTPrnrGuCbwCPAey33TXLlvumHfvsE8GNCff9y546k0A9TFgK3Ak/G2/9j+qffFPpjDfB5wqBoBeH/yYMt+6TQD5cz23MvrJvBf4ZwsHPKKi59p+pXiwih//eEUg+Ed/JlcXk5IRRheh+tjNt63W8A9wI/AHYBdxH6I7V+mHI6/rwS158jvAGcJa3++FXgO8B/AxeA5wkl4dT6odl8/k+cjttXtmyvVZ+keHLXAPB3hDJHsy/RqNdtYfoBnMWEcsBJqvnOhE5aT6PGn3I//DuwNi6PEvoitf64mTDb7X2E57MT+Cxp9cMw0w/uzve5HybMChughgd3Ib2Tuz5GqGm/RihzHCH8owwRDnTONGXrcUL/jAG/3c3Gdsl6GrN6Uu6Hmwkj/tcJI91rSbM/HqMxnXMn4RNyKv2wi3Bs46eE458PUey5T03nPAH8VcdbLUmSJEmSJEmSJEmSJEmSJEmSJEm6vP8H1H8f+1fxAxIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10efd4c50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.hist(distances, bins=1000)\n",
    "plt.xlim(0, 1000)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
